<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加--${site.name}</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="description" content="${site.description}"/>
    <meta name="keywords" content="${site.keywords}"/>
    <meta name="author" content="${site.author}"/>
    <link rel="icon" href="${site.logo}">
    <link rel="stylesheet" href="${base}/static/layui/css/layui.css" media="all" />
    <style type="text/css">
        .layui-form-item .layui-inline{ width:33.333%; float:left; margin-right:0; }
        @media(max-width:1240px){
            .layui-form-item .layui-inline{ width:100%; float:none; }
        }
        .layui-form-item .role-box {
            position: relative;
        }
        .layui-form-item .role-box .jq-role-inline {
            height: 100%;
            overflow: auto;
        }

    </style>
</head>
<!--
1:描述
2：控件类型(input/radio/checkbox/switch/textarea/editor/timer/upload)
3:是否可空YES/NO
4:默认值true/false
5:列表显示true/false
6:列表搜索true/false
-->
<body class="childrenBody">
<form class="layui-form">
	<input type="hidden" name="skillId" value="${skillId}">
    <div class="layui-form-item">
        <label class="layui-form-label"> sku商品</label>
        <div class="layui-input-block">
			<input  type="hidden" readonly  class="layui-input"  id="skuId" name="skuId" lay-verify="required" >
            <input  type="text" readonly  class="layui-input"  id="skuName" name="skuName" lay-verify="required" placeholder="请选择商品">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"> 销售价</label>
        <div class="layui-input-inline">
			<input  type="text" readonly  class="layui-input"  id="oldPrice" name="oldPrice" lay-verify="required" >
        </div>
         <div class="layui-form-mid layui-word-aux">元</div>
    </div>
     <div class="layui-form-item">
        <label class="layui-form-label"> 数量</label>
        <div class="layui-input-inline">
			<input  type="text"  class="layui-input"  id="num" name="num" lay-verify="required" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"> 秒杀价</label>
         <div class="layui-input-inline">
      	  <input  type="text"  class="layui-input"  id="skillPrice" name="skillPrice" lay-verify="required" >
        </div>
         <div class="layui-form-mid layui-word-aux">元</div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="addMallSkillSku">立即提交</button>
             <button class="layui-btn layui-btn-primary" onclick="parent.layer.close(parent.layer.getFrameIndex(window.name)); ">关闭</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="${base}/static/layui/layui.js"></script>
<script type="text/javascript" src="${base}/static/layui/xm-select.js"></script>
<script>
    layui.config({
		base : "${base}/static/layui/lay/mymodules/"
	}).use(['form','jquery','layer','tableSelect'],function(){
        var form      = layui.form,
                $     = layui.jquery,
                layer = layui.layer;

        //选择商品品
        layui.tableSelect.render({
    		elem: '#skuName',
    		checkedKey: 'id', //表格的唯一建值，非常重要，影响到选中状态 必填
    		searchKey: 's_name',	//搜索输入框的name值 默认keyword
    		searchPlaceholder: '搜索商品名称',	//搜索输入框的提示文字 默认关键词搜索
    		table: {
    			url: '${base}${adminPrefix}/mall-psku/list?s_delFlag=false',
    			method:'post',
    			cols: [[
    				{ type: 'radio' },
    				{ field: 'id', title: 'ID',hide:true },
    				{ field: 'skuno', title: 'SKU编码',width:'20%'  },
    				{ field: 'name', title: '商品名称',width:'35%'  },
    				{ field: 'priceSale', title: '销售价(元)' },
    				{ field: 'priceCost', title: '成本价(元)' },
    			]]
    		},
    		done: function (elem, data) {
    			//console.log(data)
    			var NEWJSON = []
    			var ids = []
    			layui.each(data.data, function (index, item) {
    				NEWJSON.push(item.name)
    				ids.push(item.id)
    				console.log(item)
        			$('#oldPrice').val(item.priceSale);
    			})
    			elem.val(NEWJSON.join(","))
    			$('#skuId').val(ids.join(","));
    		}
    	})

        form.on("submit(addMallSkillSku)",function(data){

            var loadIndex = layer.load(2, {
                shade: [0.3, '#333']
            });
            $.post("${base}${adminPrefix}/mall-skill-sku/add",data.field,function(res){
                layer.close(loadIndex);
                if(res.success){
                    parent.layer.msg("添加成功！",{time:1000},function(){
                        parent.layer.close(parent.addIndex);
                        //刷新父页面
                        parent.location.reload();
                    });
                }else{
                    layer.msg(res.message);
                }
            });
            return false;
        });

    });
</script>
</body>
</html>